#include"DirScanner.h"
#include <sys/types.h>
#include <dirent.h>
#include<iostream>

using std::cout;
using std::cerr;

//传递绝对目录
DirScanner::DirScanner(string& dirpath)
{
    cout<<dirpath<<"   this dir \n";
    DIR* dir= opendir(dirpath.c_str());
    if(!dir)
    {
        cout<<" open dir failed -Dirscanner.cc -16\n";
    }
    struct dirent* content;
    while((content=readdir(dir))!=nullptr)
    {
        string filename= content->d_name;
        if(content->d_type==DT_REG)
        {
            _path.push_back(dirpath+"/"+filename);
        }
        else if(content->d_type==DT_DIR)
        {
            if(filename!="."&&filename!="..")
            {
                string cndirpath = dirpath+"/"+filename;
                DIR * cndir = opendir(cndirpath.c_str());
                struct dirent * cncontext;
                while((cncontext=readdir(cndir))!=nullptr)
                {
                    string cnname= cncontext->d_name;
                    if(cncontext->d_type==DT_REG)
                    {
                        _path.push_back(cndirpath+"/"+cnname);
                    }
                }
            }
        }
    }
    //扫描文件
}
vector<string>& DirScanner::getpath()
{
    return _path;
}
